// Animator Creators
// (c) jimon game studio

#ifndef JEH_JEANIMATORCREATORS
#define JEH_JEANIMATORCREATORS

#include "ISceneManager.h"
#include "jeSpriteFrameAnimator.h"
#include "jeScriptAnimator.h"
#include "jeMouseRotateAnimator.h"
#include "jeKeyMoverAnimator.h"

namespace je
{
	namespace scene
	{
		template <class T>
		class AnimatorFactoryCreator_Desc:public ISceneManager::AnimatorFactoryType::BaseTypeCreator
		{
		public:
			AnimatorFactoryCreator_Desc(scene::ISceneManager * SceneManager){}

			IAnimator * Create()
			{
				IAnimator * NewCreate = NULL;
				JENEW(NewCreate, T )
				return NewCreate;
			}
		};

		template <class T>
		class AnimatorFactoryCreator_DescSceneManager:public ISceneManager::AnimatorFactoryType::BaseTypeCreator
		{
		protected:
			scene::ISceneManager * CurrentSceneManager;
		public:
			AnimatorFactoryCreator_DescSceneManager(scene::ISceneManager * SceneManager)
				:CurrentSceneManager(SceneManager)
			{
			}
			IAnimator * Create()
			{
				IAnimator * NewCreate = NULL;
				JENEW(NewCreate, T (CurrentSceneManager))
				return NewCreate;
			}
		};

		template<class T>
		void RegisterAnimType(ISceneManager::AnimatorFactoryType * Factory,scene::ISceneManager * SceneManager,const jeStringc & Name)
		{
			ISceneManager::AnimatorFactoryType::BaseTypeCreator * Creator = NULL;
			JENEW(Creator,T(SceneManager))
			Factory->RegisterDiscribedClass(Name,Creator);
		}

		#define ADD_ANIM_FACTORY_TYPE_D(__Name) typedef AnimatorFactoryCreator_Desc< C##__Name > FactoryCreator_C##__Name ;\
											RegisterAnimType< FactoryCreator_C##__Name >(Factory,SceneManager, #__Name );

		#define ADD_ANIM_FACTORY_TYPE_D_FREE(__Name, __Name2) typedef AnimatorFactoryCreator_Desc< __Name > FactoryCreator_##__Name2 ;\
											RegisterAnimType< FactoryCreator_##__Name2 >(Factory,SceneManager, #__Name2 );

		#define ADD_ANIM_FACTORY_TYPE_DS(__Name) typedef AnimatorFactoryCreator_DescSceneManager< C##__Name > FactoryCreator_C##__Name ;\
											RegisterAnimType< FactoryCreator_C##__Name >(Factory,SceneManager, #__Name );

		#define ADD_ANIM_FACTORY_TYPE_DS_FREE(__Name, __Name2) typedef AnimatorFactoryCreator_DescSceneManager< __Name > FactoryCreator_##__Name2 ;\
											RegisterAnimType< FactoryCreator_##__Name2 >(Factory,SceneManager, #__Name2 );

		void RegisterAnimTypes(ISceneManager::AnimatorFactoryType * Factory,scene::ISceneManager * SceneManager)
		{
			ADD_ANIM_FACTORY_TYPE_D_FREE(jeSpriteFrameAnimator,SpriteFrameAnimator)
			ADD_ANIM_FACTORY_TYPE_D_FREE(jeScriptAnimator,ScriptAnimator)
			ADD_ANIM_FACTORY_TYPE_DS_FREE(jeMouseRotateAnimator,MouseRotateAnimator)
			ADD_ANIM_FACTORY_TYPE_DS_FREE(jeKeyMoverAnimator,KeyMoverAnimator)
		}
	}
}

#endif
